﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UI;
using Base.Custom;
using DG.Tweening;
public class Button1 : BasePanel {
    public Object _object;
    private CanvasGroup canvasGroup;
    private Stack<SingleObject> singleObj;
    private Transform Mainform;
    private GameObject player;
    // Use this for initialization
    void Awake() {
        singleObj = new Stack<SingleObject>();
        canvasGroup = GetComponent<CanvasGroup>();
        Mainform = GameObject.Find("Main()").transform;
    }
    public override void OnEnter()
    {
        canvasGroup.blocksRaycasts = true;
        canvasGroup.DOFade(1, 0.6f);
        gameObject.SetActive(true);
    }
    public override void OnExit()
    {
        canvasGroup.blocksRaycasts = false;
        canvasGroup.DOFade(0, 0.6f);
        gameObject.SetActive(false);
    }
    // Update is called once per frame
    void Update() {
        if (Input.GetKeyDown(KeyCode.Escape))
        {
            结束漫游();
        }
    }
    public void yingcang()
    {
        SingleObject sobj = FreeCamera.freecamera.singleobj;
        if (sobj != null)
        {
            singleObj.Push(sobj);
            sobj.go.SetActive(false);
        }
    }
    public void xianshi()
    {
        if (singleObj.Count != 0)
        {
            SingleObject sobj = singleObj.Pop();
            sobj.go.SetActive(true);
        }
    }
    public void xianshiAll()
    {
        for (int i = singleObj.Count; i > 0; i--)
        {
            SingleObject sobj = singleObj.Pop();
            sobj.go.SetActive(true);
        }
    }

    public void message(string panelTypeString)
    {
        UIPanelType panelType = (UIPanelType)System.Enum.Parse(typeof(UIPanelType), panelTypeString);
        UIManager.Instance.PopPanel(this);
        UIManager.Instance.PushPanel(panelType);
    }
    public void 漫游()
    {
        if (player == null)
        {
            player = Instantiate(_object) as GameObject;
            player.transform.position = Mainform.position;
        }
        else
            player.SetActive(true);
        FreeCamera.freecamera.gameObject.SetActive(false);
    }
    public void 结束漫游()
    {
        player.SetActive(false);
        FreeCamera.freecamera.gameObject.SetActive(true);
    }
    public void OnClick(UIPanelType uIPanel)
    {
        UIManager.Instance.PopPanel(this);
        //UIManager.Instance.PushPanel(uIPanel);
    }
}
